﻿<h2>@Model.Name</h2>

<h3>Digibiz Advanced Media Picker</h3>
@{
    if (Model.HasValue("Media")) {
        dynamic mediaItems = Model.Media.mediaItem;
        if (mediaItems.Count() != 0)
        {
            <ul>
            @foreach (var item in mediaItems)
            {
                var image = item.Image;
                <li>
                    Original image: <a href="@image.umbracoFile">@image.nodeName</a> (@image.umbracoBytes bytes)<br />
                
                    @*
                        If the type of the mediacropper is not XML (but a string) then there 
                        are no crops defined, so don't try to find the crops.
                    *@
                    @{ var crops = image.mediaCropper; }
                    @if (crops.GetType().ToString() != "System.String")
                    {
                        <text>Crops:</text><br />
                        @* Find the crop with the name "Thumbnail" and "Header" and 
                            put the url property in image's source attribute *@
                        <img src="@crops.Find("@name", "Thumbnail").url" alt="@image.nodeName"/><br />
                        <img src="@crops.Find("@name", "Header").url" alt="@image.nodeName"/>
                    }
                </li>
            }
            </ul>
        }
    }
}